// 随机数字符数组
var baseChars = ['0','1','2','3','4','5','6','7','8','9','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

var baseNumbers = ['0','1','2','3','4','5','6','7','8','9'];

// 随机获取单个字符
function randSingleChar(base) {
  var rand  = Math.random();
  var index = Math.round(rand * base.length);
  
  return base[index];
}

module.exports = {
  /* 
   * 功能描述: 获取随机代码串
   * 参数描述:
   *   n: 代码串长度
   */
  genRandomChars: function(n) {
    var result = new Array(n);

    for(var i = 0; i < n; i++) {
      result[i] = randSingleChar(baseChars);
    }

    return result.join('');
  },
  genRandomNumbers: function(n) {
    var result = new Array(n);

    for(var i = 0; i < n; i++) {
      result[i] = randSingleChar(baseNumbers);
    }

    return result.join('');
  }
}
